﻿using Entitas;
/// <summary>
/// takes the current equipped weapon by the player and the current player direction and plays the corresponding animation
/// </summary>
class WeaponAttackAnimationSystem : IExecuteSystem
{
    PlayerContext playerContext;
    public WeaponAttackAnimationSystem(Contexts contexts)
    {
        playerContext = contexts.player;
    }
    public void Execute()
    {
        if (playerContext.count == 1)
        {
            var player = playerContext.GetEntities().SingleEntity<PlayerEntity>();

            if (!player.isAttacking && player.hasEquippedWeapon)
            {
                if (ServiceManager.InputService.MousePressed)
                {
                    player.isAttacking = true;

                    if (player.hasAnimator)
                    {
                        switch (player.direction.value)
                        {
                            case Direction.Up:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.UpAnimation);
                                break;
                            case Direction.Up_Left:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.UpAnimation);
                                break;
                            case Direction.Up_Right:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.UpAnimation);
                                break;
                            case Direction.Down:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.DownAnimation);
                                break;
                            case Direction.Down_Left:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.DownAnimation);
                                break;
                            case Direction.Down_Right:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.DownAnimation);
                                break;
                            case Direction.Left:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.LeftAnimation);
                                break;
                            case Direction.Right:
                                player.animator.Value.PlayAnimation(player.equippedWeapon.value.RightAnimation);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }
    }
}


